﻿
@{
    ViewBag.Title = "Index Test JsTree";
    
    KPIS.GERP.Models.GERPContext context = new KPIS.GERP.Models.GERPContext();

        
    IEnumerable<WarehousePermit> modelWh = (from wh in context.WarehousePermits
                                            join js in context.JobSites on wh.JobSiteId equals js.JobSiteId
                                            join w in context.Warehouses on wh.WhId equals w.WhId
                                            select wh).ToList();

    IEnumerable<IGrouping<int, int?>> query =
        modelWh.GroupBy(x => x.WhId, x=> x.JobSiteId);

    //List<smth> list = new List<smth>();
    //IEnumerable<IGrouping<int, smth>> groups = list.GroupBy(x => x.id);
    //IEnumerable<smth> smths = groups.SelectMany(group => group);
    //List<smth> newList = smths.ToList();
    
}

<h2>@ViewBag.Title</h2>




<div id="demo" class="demo span4" style="height: 100px;">
    @foreach (var item in query)
    {        
        <ul>
            @if (item != null)
            { 
                <li  id="@item.Key"><a href="#">@item.Key</a>
                    @foreach (var node in modelWh.Where(x=>x.WhId == item.Key))
                    {
                        <ul>
                            @if(node!=null)
                            {
                                <li id="@node.JobSiteId">
                                    <a href="#">@node.JobSiteId</a>
                                </li>
                            }
                        </ul>
                    }
                </li>
           }
        </ul>
    
    }
</div>@*<div id="demo" class="demo" style="height:100px;">
	<ul>
		<li rel="team" id="shtml_1" class="jstree-open">
			<a href="#">Root node 1</a>
			<ul>
				<li rel="iteration" id="shtml_2">
					<a href="#">Child node 1</a>
				</li>
				<li rel="iteration" id="shtml_3">
					<a href="#">Child node 2</a>
				</li>
			</ul>
		</li>
		<li rel="team" id="shtml_4">
			<a href="#">Root node 2</a>
		</li>
	</ul>
</div>*@

@section scripts{

    <link href="~/Content/jstree-v.pre1.0/themes/default/style.css" rel="stylesheet" />
    <script src="~/Content/jstree-v.pre1.0/_docs/syntax/!script.js"></script>
    <script src="~/Content/jstree-v.pre1.0/_lib/jquery.cookie.js"></script>
    <script src="~/Content/jstree-v.pre1.0/_lib/jquery.hotkeys.js"></script>
    <script src="~/Content/jstree-v.pre1.0/_lib/jquery.js"></script>
    <script src="~/Content/jstree-v.pre1.0/jquery.jstree.js"></script>



    <script type="text/javascript" >


        $("#demo").jstree({
            "types": {
                "types": {
                    "team": {
                        "icon": {
                            "image": "../Content/themes/base/images/animated-overlay.gif"
                        }
                    },

                    "iteration": {
                        "icon": {
                            "image": "../Content/themes/base/minified/images/ui-icons_cd0a0a_256x240.png"
                        }
                    }
                }
            },
            "ui": {
                "select_limit": 2,
                "select_multiple_modifier": "alt",
                "selected_parent_close": "select_parent",
                "initially_select": ["phtml_2"]
            },
            "core": { "initially_open": ["phtml_1"] },
            "plugins": ["html_data", "types", "themes", "ui"]
        })
        .bind("select_node.jstree", function (event, data) {
            // `data.rslt.obj` is the jquery extended node that was clicked
            alert(data.rslt.obj.attr("id"));
        });


    </script>
}


